var app=getApp(),api=require('../../../../api.js');
Page({
  data: {
    showList:true,
    couponArr: []
  },
  onShow:function(){
    app.pageOnLoad(this);
    var that=this;
    that.setData({
      site: wx.getStorageSync('site')
    })
    that.getRedList();
  },
  // get红包列表
  getRedList: function(){ 
    let that = this;
    app.request({
      url: api.Coupon.actRed,
      data: {
        uid: wx.getStorageSync('uid'),
        bid: wx.getStorageSync('bid')
      },
      success: function (e) {
        console.log(e);
        let list = e.data;
        if (e.code == 1) {
          that.setData({
            couponArr: e.data
          })
        }else{
          that.setData({
            showList:false
          })
        }
      }
    })
  },
  receive: function(e){
    let that = this;
    let disid = e.target.dataset.id; 
    let money = e.target.dataset.money;
    let createtime = e.target.dataset.createtime;
    let pasttime = e.target.dataset.pasttime;
    app.request({
      url: api.Coupon.getActCoupon,
      data: {
        uid: wx.getStorageSync('uid'),
        disid: disid,
        createtime:createtime,
        pasttime:pasttime
      },
      success: function (ress) {
        if (ress.code == 1) {
          wx.showModal({
            title: '提示',
            content: '恭喜你获得' + money + '元红包',
            showCancel: false
          })
          that.getRedList();
        }else{
          wx.showModal({
            title: '提示',
            content: ress.msg,
            showCancel: false
          })
        }
      }
    })
  }
})